import random

import pygame
from pygame.sprite import Sprite


class Ball(Sprite):
    def __init__(self, ai_settings, screen):

        super().__init__()
        self.screen = screen
        self.ai_settings = ai_settings

        self.image = pygame.image.load('images/ball.bmp')
        self.rect = self.image.get_rect()

        available_number_x = int((ai_settings.screen_width - (2 * self.rect.width))/self.rect.width)

        self.x = float(self.rect.width * available_number_x * random.random())
        # self.rect.x = self.rect.width
        self.rect.x = self.x
        self.rect.y = self.rect.height
        # print(self.x)
        self.update()


    def update(self):

        self.drop_speed_factor = 1
        self.rect.y += self.drop_speed_factor
        #self.rect.y = self.y


    def blitme(self):
        self.screen.blit(self.image, self.rect)